package com.cc.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cc.entity.Employees;
import com.cc.service.IEmployeesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
/**
 * <p>
 * 员工登录表 前端控制器
 * </p>
 *
 * @author cc
 * @since 2024-12-09
 */
@RestController
@RequestMapping("/employees")
public class EmployeesController {
    @Autowired
    private IEmployeesService employeeService;

    @GetMapping("/login")
    public String login() {
        return "login";
    }

    // 获取分页数据
    @GetMapping("/page")
    public Page<Employees> getEmployeePage(@RequestParam int current, @RequestParam int size) {
        Page<Employees> page = new Page<>(current, size);
        return employeeService.page(page);
    }

    // 通过员工Id获取员工信息
    @GetMapping("/{id}")
    public Employees getEmployeeById(@PathVariable Long id) {
        return employeeService.getById(id);
    }

    // 新增员工
    @PostMapping
    public boolean addEmployee(@RequestBody Employees employee) {
        return employeeService.save(employee);
    }

    // 修改员工信息
    @PutMapping
    public boolean updateEmployee(@RequestBody Employees employee) {
        return employeeService.updateById(employee);
    }

    // 删除员工
    @DeleteMapping("/{id}")
    public boolean deleteEmployee(@PathVariable Long id) {
        return employeeService.removeById(id);
    }
}